﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    /// <summary>
    /// 获取消息集概况列表
    /// POST
    /// url:
    ///     ./api/v1.1/action.ashx?sys:cmd=sendverifycode4registerbyphon
    /// form:
    ///     op:phone
    /// </summary>
    class SendVerifycode4RegisterByPhoneAction : PostAction<Params.SendVerifycode4RegisterByPhoneParams, Results.SendVerifycode4RegisterByPhoneResult>
    {
        protected override ActionResult<Results.SendVerifycode4RegisterByPhoneResult> OnExecute(ActionContext context, SysParameters sysParameters, Params.SendVerifycode4RegisterByPhoneParams opParams)
        {
            int minute = 5;
            VerifycodeService service = new VerifycodeService();
            ServiceResult<Verifycode> serviceResult = service.Send4RegisterByPhone(opParams.Phone, minute);

            Results.SendVerifycode4RegisterByPhoneResult actionResult = new Results.SendVerifycode4RegisterByPhoneResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                actionResult.Code = serviceResult.Data.Value;
                actionResult.TimeoutMinute = minute;

                return new ActionResult<Results.SendVerifycode4RegisterByPhoneResult>(true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }

            return new ActionResult<Results.SendVerifycode4RegisterByPhoneResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
